package com.lagou.config;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * @author Nocturne
 * @date 2021/5/10 10:23
 * @description 切面类
 * 使用AOP优化：就是对标注了注解的方法进行拦截增强，在拦截增强过程中，对注解进行解析，拿到里面的value值，根据值再去构建RoutingDataSourceContext routingDataSourceContext = new RoutingDataSourceContext(key)对象
 */

@Aspect
@Component
public class RoutingAspect {

	/** 对被@RoutingWith标注方法进行拦截增强，环绕通知类型 */
	@Around("@annotation(routingWith)")
	public Object routingWithDataSource(ProceedingJoinPoint joinPoint, RoutingWith routingWith) throws Throwable {
		// value的值就是需要的key值
		String value = routingWith.value();
		RoutingDataSourceContext routingDataSourceContext = new RoutingDataSourceContext(value);
		return joinPoint.proceed();
	}


}
